$(document).ready(function () {
    var length,
    currentIndex = 0,
    interval,
    hasStarted = false, 
    t = 1200000; //轮播时间间隔 
    length = $('.slider_1-panel').length;
    //将除了第一张图片隐藏 
            $('.slider_1-panel:not(:first)').hide();
            //将第一个slider-item设为激活状态 
            $('.slider_1-item:first').addClass('slider_1-item-selected');
            //隐藏向前、向后翻按钮 
            $('.slider_1-page').hide();
            //鼠标上悬时显示向前、向后翻按钮,停止滑动，鼠标离开时隐藏向前、向后翻按钮，开始滑动 
            $('.slider_1-panel, .slider_1-pre, .slider_1-next').hover(function () {
                stop();
                $('.slider_1-page').show();
            }, function () {
                $('.slider_1-page').hide();
                start();
            });
            $('.slider_1-item').hover(function (e) {
                stop();
                var preIndex = $(".slider_1-item").filter(".slider_1-item-selected").index();
                currentIndex = $(this).index();
                play(preIndex, currentIndex);
            }, function () {
                start();
            });
//          $('.slider_1-pre').unbind('click');
            $('.slider_1-pre').bind('click', function () {
                pre();
            });
//          $('.slider_1-next').unbind('click');
            $('.slider_1-next').bind('click', function () {
                next();
            });
            /** 
             * 向前翻页 
             */
            function pre() {
                var preIndex = currentIndex;
                currentIndex = (--currentIndex + length) % length;
                play(preIndex, currentIndex);
            }
            /** 
             * 向后翻页 
             */
            function next() {
                var preIndex = currentIndex;
                currentIndex = ++currentIndex % length;
                play(preIndex, currentIndex);
            }
            /** 
             * 从preIndex页翻到currentIndex页 
             * preIndex 整数，翻页的起始页 
             * currentIndex 整数，翻到的那页 
             */
            function play(preIndex, currentIndex) {
                $('.slider_1-panel').eq(preIndex).fadeOut(500)
                .parent().children().eq(currentIndex).fadeIn(1000);
                $('.slider_1-item').removeClass('slider_1-item-selected');
                $('.slider_1-item').eq(currentIndex).addClass('slider_1-item-selected');
            }
            /** 
             * 开始轮播 
             */
            function start() {
                if (!hasStarted) {
                    hasStarted = true;
                    interval = setInterval(next, t);
                }
            }
            /** 
             * 停止轮播 
             */
            function stop() {
                clearInterval(interval);
                hasStarted = false;
            }
            //开始轮播 
            start();
        });